package org.arch_learn.dubbo_demo.service_consumer;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.arch_learn.dubbo_demo.service_consumer.service.HelloServiceConsumer;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;

public class DubboStressTestMain {
    public static void main(String[] args) throws IOException, InterruptedException {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(DubboConsumerMain.ConsumerConfig.class);
        applicationContext.start();
        //获取消费者组件
        final HelloServiceConsumer consumer = applicationContext.getBean(HelloServiceConsumer.class);

        for (int i = 0; i < 1000; i++) {
            Thread.sleep(5);
            new Thread(new Runnable() {
                public void run() {
                    String hello = consumer.sayHello("world");
                    System.out.println("result:" + hello);
                }
            }).start();
        }
    }

    @Configuration
    @EnableDubbo
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "org.arch_learn.dubbo_demo.service_consumer.service")
    static class ConsumerConfig {

    }
}
